﻿using Curry.Forum.Facade;
using Curry.Forum.Facade.Enum;
using Curry.Forum.Query.Service;
using Curry.Forum.Query.Service.Dapper;
using Curry.Forum.Query.Service.DTOS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Curry.Forum.Query.Command
{
    public class ArticleCommand
    {
        private IArticleQueryService _articleQueryService;
        public ArticleCommand(IArticleQueryService articleQueryService)
        {
            _articleQueryService = articleQueryService;
        }

        /// <summary>
        /// 获取所有的文章
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public BasicResponse GetAllArticle(int pageIndex, int pageSize)
        {
            BasicResponse response = new BasicResponse();
            try
            {
                object data = _articleQueryService.GetArticleList(pageIndex, pageSize);
                if (data != null)
                    response.PostData = data;
                else
                {
                    response.RtnCode = (int)ReturnedCodeEnum.未查询到数据;
                    response.ErrorMsg = ReturnedCodeEnum.未查询到数据.ToString();
                }
            }
            catch (Exception ex)
            {
                response.RtnCode = (int)ReturnedCodeEnum.查询失败;
                response.ErrorMsg = ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 根据Id查询文章明细数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public BasicResponse GetArticleById(string Id)
        {
            BasicResponse response = new BasicResponse();
            try
            {
                object data = _articleQueryService.GetArticleById(Id);
                if (data != null)
                    response.PostData = data;
                else
                {
                    response.RtnCode = (int)ReturnedCodeEnum.未查询到数据;
                    response.ErrorMsg = ReturnedCodeEnum.未查询到数据.ToString();
                }
            }
            catch (Exception ex)
            {
                response.RtnCode = (int)ReturnedCodeEnum.查询失败;
                response.ErrorMsg = ex.Message;
            }
            return response;
        }
    }
}
